package com.itstherules.jmsunit.expectation.xml;

import org.junit.Test;

import com.itstherules.jmsunit.expectation.xml.xpath.XPathDoesntExistExpectation;

public class XPathDoesntExistExpectationTest {

	private static String XML = "<root>" + "<shoot>" + "<abba/>"
			+ "<acdc></acdc>" + "<eno>eno</eno>" + "</shoot>" + "<boot>"
			+ "<UNKLE>UNKLEMix</UNKLE>" + "<lfo>lowFrequencyOscillation</lfo>"
			+ "<soundgarden>superunknown</soundgarden>" + "</boot>" + "</root>";

	@Test
	public void xPathDoesntExist() throws Exception {
		XPathDoesntExistExpectation unit = new XPathDoesntExistExpectation("/root/shoot/fruit");
		unit.compute(XML);
	}
	
	@Test
	public void xPathDoesntExistAlso() throws Exception {
		XPathDoesntExistExpectation unit = new XPathDoesntExistExpectation("/root/astute");
		unit.compute(XML);
	}

	@Test(expected = IllegalArgumentException.class)
	public void nullXPath() throws Exception {
		XPathDoesntExistExpectation unit = new XPathDoesntExistExpectation(null);
		unit.compute(XML);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public void xPathNullInvalidXpath() throws Exception {
		XPathDoesntExistExpectation unit = new XPathDoesntExistExpectation("im_a/lovely!@bunch_of_nonsense\\d");
		unit.compute(XML);
	}

	@Test(expected = AssertionError.class)
	public void xPathExistsWhenNull() throws Exception {
		XPathDoesntExistExpectation unit = new XPathDoesntExistExpectation("/root/shoot/abba");
		unit.compute(XML);
	}

	@Test(expected = AssertionError.class)
	public void xPathExistsAndEmptyString() throws Exception {
		XPathDoesntExistExpectation unit = new XPathDoesntExistExpectation("/root/shoot/acdc");
		unit.compute(XML);
	}

	@Test(expected = AssertionError.class)
	public void xPathNullExistsWithValue() throws Exception {
		XPathDoesntExistExpectation unit = new XPathDoesntExistExpectation("/root/shoot/eno");
		unit.compute(XML);
	}


}
